package com.easy.stock.util;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class JsoupUtil {
	
	public static String getElemHtml(Element parent, String selector, boolean must) {
		if(must) {
			return parent.select(selector).get(0).html().trim();
		}
		
		Elements elems = parent.select(selector);
		if(elems.size()<=0)
			return "";
		return elems.get(0).html().trim();
	}
	
	public static String getElemText(Element parent, String selector, boolean must) {
		if(must) {
			return parent.select(selector).get(0).text().trim();
		}
		
		Elements elems = parent.select(selector);
		if(elems.size()<=0)
			return "";
		return elems.get(0).text().trim();
	}
	
	
	
	public static String getElemProp(Element parent, String selector, String propName, boolean must) {
		if(must) {
			return parent.select(selector).get(0).attr(propName);
		}
		
		Elements elems = parent.select(selector);
		if(elems.size()<=0)
			return "";
		return elems.get(0).attr(propName);
	}

}
